=install kernel development env=
<pre>
sudo apt-get update
sudo apt-get install linux-source
</pre>
=build/install libpri. =
* [https://issues.asterisk.org/jira/browse/PRI-145?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel bug]: apply the patch.
<pre>
wget http://downloads.asterisk.org/pub/telephony/libpri/releases/libpri-1.4.13.tar.gz
tar -xzf libpri-1.4.13.tar.gz
cd libpri-1.4.13
wget https://issues.asterisk.org/jira/secure/attachment/44869/fix_unused_write.patch
patch  -i fix_unused_write.patch
make
sudo make install
cd ..
</pre>
= build/install DAHDI=
# refer to [http://wiki.freeswitch.org/wiki/OpenZap_Dahdi link]. similar steps.
# refer to [http://wiki.freeswitch.org/wiki/FreeTDM link] for general introducing about freetdm.
# refer to [http://wiki.freeswitch.org/wiki/Freetdm.conf_Examples#Digium_TDM400 sample conf] for Digium TDM400 sample conf.

<pre>
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.6.1+2.6.1.tar.gz
tar -zxvf dahdi-linux-complete-2.6.1+2.6.1.tar.gz
cd dahdi-linux-complete-2.6.1+2.6.1
make
sudo make install
sudo make config
dahdi_genconf modules
edit /etc/udev/rules.d/dahdi.rules to enable freeswitch access.
edit /usr/local/freeswitch/auto*/modules* to allow freetdm to be loaded at start.
cd ..
</pre>

=== sample dahdi rules ===
<pre>
# udev rules to generate the /dev/dahdi device files (if not yet provided 
# by your distribution):
KERNEL=="dahdictl", NAME="dahdi/ctl"
KERNEL=="dahditranscode", NAME="dahdi/transcode"
KERNEL=="dahditimer", NAME="dahdi/timer"
KERNEL=="dahdichannel", NAME="dahdi/channel"
KERNEL=="dahdipseudo", NAME="dahdi/pseudo"
KERNEL=="dahdi[0-9]*", NAME="dahdi/%n"

# DAHDI devices with ownership/permissions for running as non-root
# SUBSYSTEM=="dahdi",  OWNER="asterisk", GROUP="asterisk", MODE="0660"
SUBSYSTEM=="dahdi",  OWNER="luna", GROUP="luna", MODE="0660"
</pre>

==some hints on dialplan, configuration==
* freetdm.conf: copy conf from [http://wiki.freeswitch.org/wiki/Freetdm.conf_Examples#Digium_TDM400 sample]. 
<pre>
[span zt FXS1]
fxs-channel => 3

[span zt FXS2]
fxs-channel => 4

[span zt FXO1]
fxo-channel => 1

[span zt FXO2]
fxo-channel => 2
; comment all other span
</pre>
* autoload_configs/freetdm.conf.xml
<pre>
 <analog_spans>
    <!-- The span name must match the name in your freetdm.conf -->
    <span name="FXO1">
    <!-- ..... all other default values -->
 </analog_spans>
</pre>
* dialplan sample:
<pre>
    <!-- any dial start with 0, will go out to telephone lane -->
    <extension name="call me">
      <condition field="destination_number" expression="^0(\d+)$">
        <action application="bridge" data="freetdm/FXO1/a/$1"/>
      </condition>
    </extension>

  <!-- any dial in number can accept a number to dial to VOIP number -->
  <extension name="bridge-FXS-to-FXO">
  <condition field="destination_number" expression="^.+$" />
  <condition field="chan_name" expression="^FreeTDM" >
    <action application="answer" />
    <action application="play_and_get_digits" data="4 11 1 5000 # ivr/ivr-enter_destination_telephone_number.wav ivr/ivr-that_was_an_invalid_entry.wav target_num \d+"/>
        <!-- add this call to the conference -->
    <action application="bridge" data="user/${target_num}"/>
  </condition>
</extension>

</pre>

=build freeswitch=
*# edit modules.conf to allow mod_freetdm.
<pre>
./bootstrap
./configure
make
make install
make cd-sounds-install cd-moh-install
</pre>